home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decodeyuv2.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  6KB  |  281 lines

  1. /*
  2. sc:c/sc opt txt/DecodeYUV2.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "YUV.h"
  7. #include "GlobalVars.h"
  8. #include "Utils.h"
  9.  
  10. struct YUV2Data {
  11.   ulong dummy;
  12. };
  13.  
  14. void __regargs YUV211111toRGB(uchar *image, ulong width, ulong height, ulong ix, ulong iy);
  15. void __regargs YUV211111to332(uchar *image, ulong width, ulong height, ulong ix, ulong iy);
  16. void __regargs YUV211111to332Dith(uchar *image, ulong width, ulong height, ulong ix, ulong iy);
  17.  
  18. void __regargs (*yuv211111) (uchar *image, ulong width, ulong height, ulong ix, ulong iy);
  19. ulong yuv2RowIncMult;
  20.  
  21. /* /// "SelectYUV2Funcs()" */
  22. __asm void SelectYUV2Funcs(REG(a0) struct YUV2Data *spec,
  23.                            REG(d0) uchar _gray,
  24.                            REG(d1) uchar _dither)
  25. {
  26.   if (_gray) {
  27.     yuv211111=YUV211111to332;
  28.     yuv2RowIncMult=1;
  29.   } else if (_dither) {
  30.     yuv211111=YUV211111to332Dith;
  31.     yuv2RowIncMult=1;
  32.   } else {
  33.     yuv211111=YUV211111toRGB;
  34.     yuv2RowIncMult=4;
  35.   }
  36. }
  37. /* \\\ */
  38.  
  39. /* /// "DecodeYUV2A()" */
  40. __asm void DecodeYUV2A(REG(a0) uchar *from,
  41.                        REG(a1) uchar *to,
  42.                        REG(d0) ulong width,
  43.                        REG(d1) ulong height,
  44.                        REG(d2) ulong encSize,
  45.                        REG(a2) struct YUV2Data *spec)
  46. {
  47.   uchar *ip=to;
  48.   ulong rowInc=(width<<1)*yuv2RowIncMult;
  49.   ulong mx=width>>1;
  50.   ulong ycnt=0;
  51.   ulong y=height;
  52.  
  53.   while(y>0) {
  54.     uchar *yp, *up, *vp;
  55.     ulong x=mx;
  56.     if(ycnt==0) {
  57.       yp=yuvBuf->yBuf;
  58.       up=yuvBuf->uBuf;
  59.       vp=yuvBuf->vBuf;
  60.     }
  61.     while(x--) {
  62.       *yp++=from[0];
  63.       *up++=(from[1])^0x80;
  64.       *yp++=from[2];
  65.       *vp++=(from[3])^0x80;
  66.       from+=4;
  67.     }
  68.     ycnt++;
  69.     y--;
  70.     if((ycnt>=2) || (y==0)) {
  71.       if (gray) mycopymem((ulong *)yuvBuf->yBuf,(ulong *)ip,rowInc);
  72.       else yuv211111(ip,width,ycnt,width,ycnt);
  73.       ycnt=0;
  74.       ip+=rowInc;
  75.     }
  76.   }
  77. }
  78. /* \\\ */
  79.  
  80. /* /// "DecodeYUV2B()" */
  81. __asm void DecodeYUV2B(REG(a0) uchar *from,
  82.                        REG(a1) uchar *to,
  83.                        REG(d0) ulong width,
  84.                        REG(d1) ulong height,
  85.                        REG(d2) ulong encSize,
  86.                        REG(a2) struct YUV2Data *spec)
  87. {
  88.   uchar *ip=to;
  89.   ulong rowInc=(width<<1)*yuv2RowIncMult;
  90.   ulong mx=width>>1;
  91.   ulong ycnt=0;
  92.   ulong y=height;
  93.  
  94.   while(y>0) {
  95.     uchar *yp,*up,*vp;
  96.     ulong x=mx;
  97.     if(ycnt==0) {
  98.       yp=yuvBuf->yBuf;
  99.       up=yuvBuf->uBuf;
  100.       vp=yuvBuf->vBuf;
  101.     }
  102.     while(x--) {
  103.       *yp++=from[0];
  104.       *up++=from[1];
  105.       *yp++=from[2];
  106.       *vp++=from[3];
  107.       from+=4;
  108.     }
  109.     ycnt++;
  110.     y--;
  111.     if((ycnt>=2) || (y==0)) {
  112.       if (gray) mycopymem((ulong *)yuvBuf->yBuf,(ulong *)ip,rowInc);
  113.       else yuv211111(ip,width,ycnt,width,ycnt);
  114.       ycnt=0;
  115.       ip+=rowInc;
  116.     }
  117.   }
  118. }
  119. /* \\\ */
  120.  
  121. /* /// "YUV211111toRGB()" */
  122. void __regargs YUV211111toRGB(uchar *to,
  123.                               ulong width,
  124.                               ulong height,
  125.                               ulong ix,
  126.                               ulong iy)
  127. {
  128.   ulong mx=(width>>1);
  129.   ulong my=height;
  130.   ulong inc=width*4;
  131.   long *ubTab=yuvTab->ubTab;
  132.   long *vrTab=yuvTab->vrTab;
  133.   long *ugTab=yuvTab->ugTab;
  134.   long *vgTab=yuvTab->vgTab;
  135.   long *yTab=yuvTab->yTab;
  136.   uchar *yBuf=yuvBuf->yBuf;
  137.   uchar *uBuf=yuvBuf->uBuf;
  138.   uchar *vBuf=yuvBuf->vBuf;
  139.  
  140.   while (my--) {
  141.     RGBTriple *ip=(RGBTriple *)to;
  142.     uchar *yp=yBuf;
  143.     uchar *up=uBuf;
  144.     uchar *vp=vBuf;
  145.     ulong x=mx;
  146.     while (x--) {
  147.       ulong iu=*up++;
  148.       ulong iv=*vp++;
  149.       long v2r=vrTab[iv];
  150.       long uv2g=vgTab[iv]+ugTab[iu];
  151.       long u2b=ubTab[iu];
  152.       DecYUVRGB(ip[0],*yp++,v2r,uv2g,u2b);
  153.       DecYUVRGB(ip[1],*yp++,v2r,uv2g,u2b);
  154.       ip+=2;
  155.     }
  156.     to+=inc;
  157.     yBuf+=ix;
  158.     uBuf+=(ix>>1);
  159.     vBuf+=(ix>>1);
  160.   }
  161. }
  162. /* \\\ */
  163.  
  164. /* /// "YUV211111to332()" */
  165. void __regargs YUV211111to332(uchar *to,
  166.                               ulong width,
  167.                               ulong height,
  168.                               ulong ix,
  169.                               ulong iy)
  170. {
  171.   ulong mx=(width>>1);
  172.   ulong my=height;
  173.   long *ubTab=yuvTab->ubTab;
  174.   long *vrTab=yuvTab->vrTab;
  175.   long *ugTab=yuvTab->ugTab;
  176.   long *vgTab=yuvTab->vgTab;
  177.   long *yTab=yuvTab->yTab;
  178.   uchar *yBuf=yuvBuf->yBuf;
  179.   uchar *uBuf=yuvBuf->uBuf;
  180.   uchar *vBuf=yuvBuf->vBuf;
  181.  
  182.   while (my--) {
  183.     uchar *ip=(uchar *)to;
  184.     uchar *yp=yBuf;
  185.     uchar *up=uBuf;
  186.     uchar *vp=vBuf;
  187.     ulong x=mx;
  188.     while (x--) {
  189.       ulong iu=*up++;
  190.       ulong iv=*vp++;
  191.       long v2r=vrTab[iv];
  192.       long uv2g=vgTab[iv]+ugTab[iu];
  193.       long u2b=ubTab[iu];
  194.  
  195.       DecYUV332(ip,*yp++,v2r,uv2g,u2b);
  196.       DecYUV332(ip,*yp++,v2r,uv2g,u2b);
  197.     }
  198.     to+=width;
  199.     yBuf+=ix;
  200.     uBuf+=(ix>>1);
  201.     vBuf+=(ix>>1);
  202.   }
  203. }
  204. /* \\\ */
  205.  
  206. /* /// "YUV211111to332Dith()" */
  207. void __regargs YUV211111to332Dith(uchar *to,
  208.                                   ulong width,
  209.                                   ulong height,
  210.                                   ulong ix,
  211.                                   ulong iy)
  212. {
  213.   ulong mx=(width>>1);
  214.   ulong my=height;
  215.   long *ubTab=yuvTab->ubTab;
  216.   long *vrTab=yuvTab->vrTab;
  217.   long *ugTab=yuvTab->ugTab;
  218.   long *vgTab=yuvTab->vgTab;
  219.   long *yTab=yuvTab->yTab;
  220.   uchar *yBuf=yuvBuf->yBuf;
  221.   uchar *uBuf=yuvBuf->uBuf;
  222.   uchar *vBuf=yuvBuf->vBuf;
  223.  
  224.   while (my) {
  225.     ulong x=mx;
  226.     long re=0, ge=0, be=0;
  227.     uchar *ip0, *ip1;
  228.     uchar *yp0, *yp1;
  229.     uchar *up0, *up1;
  230.     uchar *vp0, *vp1;
  231.     ip0=to;
  232.     yp0=yBuf;
  233.     up0=uBuf;
  234.     vp0=vBuf;
  235.     if (my>1) {
  236.       ip1=ip0+width;
  237.       yp1=yp0+ix;
  238.       up1=up0+(ix>>2);
  239.       vp1=vp0+(ix>>2);
  240.       my-=2;
  241.     } else {
  242.       ip1=ip0;
  243.       yp1=yp0;
  244.       up1=up0;
  245.       vp1=vp0;
  246.       my=0;
  247.     }
  248.     while (x--) {
  249.       ulong iu, iv;
  250.       long v2r0, uv2g0, u2b0;
  251.       long v2r1, uv2g1, u2b1;
  252.       iu=*up0++;
  253.       iv=*vp0++;
  254.       v2r0=vrTab[iv];
  255.       uv2g0=vgTab[iv]+ugTab[iu];
  256.       u2b0=ubTab[iu];
  257.       iu=*up1++;
  258.       iv=*vp1++;
  259.       v2r1=vrTab[iv];
  260.       uv2g1=vgTab[iv]+ugTab[iu];
  261.       u2b1=ubTab[iu];
  262.  
  263.       DecYUV332Dith(*ip0++,*yp0++,v2r0,uv2g0,u2b0);
  264.       re>>=1; ge>>=1; be>>=1;
  265.       DecYUV332Dith(*ip1++,*yp1++,v2r1,uv2g1,u2b1);
  266.       re>>=1; ge>>=1; be>>=1;
  267.  
  268.       DecYUV332Dith(*ip1++,*yp1++,v2r1,uv2g1,u2b1);
  269.       re>>=1; ge>>=1; be>>=1;
  270.       DecYUV332Dith(*ip0++,*yp0++,v2r0,uv2g0,u2b0);
  271.       re>>=1; ge>>=1; be>>=1;
  272.     }
  273.     to+=(width<<1);
  274.     yBuf+=(ix<<1);
  275.     uBuf+=(ix>>1);
  276.     vBuf+=(ix>>1);
  277.   }
  278. }
  279. /* \\\ */
  280.  
  281.